package com.synnex.mobile.servier.web.survey.controller;

import com.synnex.mobile.generic.core.pager.DataResults;
import com.synnex.mobile.generic.core.pager.Pagination;
import com.synnex.mobile.servier.core.notification.bo.NotificationBo;
import com.synnex.mobile.servier.core.notification.bo.criteria.NotificationCriteria;
import com.synnex.mobile.servier.core.notification.service.DeviceTokenService;
import com.synnex.mobile.servier.core.notification.service.NotificationService;
import com.synnex.mobile.servier.core.survey.bo.QuestionnaireBo;
import com.synnex.mobile.servier.core.survey.bo.SurveyBo;
import com.synnex.mobile.servier.core.survey.dto.Survey;
import com.synnex.mobile.servier.core.survey.service.AnswerItemService;
import com.synnex.mobile.servier.core.survey.service.QuestionnaireService;
import com.synnex.mobile.servier.core.survey.service.SurveyService;
import com.synnex.mobile.servier.web.common.controller.AbstractController;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kerryf
 */
public abstract class AbstractSurveyController extends AbstractController {

    protected SurveyService surveyService;
    protected AnswerItemService answerItemService;
    protected QuestionnaireService questionService;

    public void setQuestionService(QuestionnaireService questionService) {
        this.questionService = questionService;
    }

    public void setSurveyService(SurveyService surveyService) {
        this.surveyService = surveyService;
    }

    public void setAnswerItemService(AnswerItemService answerItemService) {
        this.answerItemService = answerItemService;
    }

    public Map<String,Object> getSurveys(HttpServletRequest request) {

        List<SurveyBo> results =null;
        String qid = request.getParameter("qid");
        if(null!=qid && !qid.equals("") && !qid.equals("0")){

             results = surveyService.listSurvey(Integer.parseInt(qid));
        }       else{
            results = surveyService.listSurvey(null);
        }

//        for(Survey survey : results){
//            Collections.sort(survey.getAnswerItems());
//        }

        Map model = new HashMap<String,Object>();
        model.put("totalCount", results.size());
        model.put("results", results);
        return model;
    }

    public Map<String,Object> getQuestionnaires(HttpServletRequest request) {


        List<QuestionnaireBo> results = questionService.getQuestionnaires();

        Map model = new HashMap<String,Object>();
        model.put("totalCount", results.size());
        model.put("results", results);
        return model;
    }

}
